#include <stdio.h>
#include <pthread.h>

#define NR	100000000

unsigned int cnt = 0;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

void *pthread( void * );

int main( void )
{
	pthread_t tid1, tid2;
	
//        pthread_create( &tid, NULL, pthread, NULL );

	pthread_create( &tid1, NULL, pthread, NULL );
	pthread_create( &tid2, NULL, pthread, NULL );
	pthread_join( tid1, NULL );
	pthread_join( tid2, NULL );

	
	if ( cnt != (unsigned int)NR * 2 ) {
		printf( "Error!!! cnt[ %d ].\n", cnt );
	}else {
		printf( "Bingo!!! cnt[ %d ].\n", cnt );
	}

	return 0;
}

void * pthread( void *arg ) 
{
	int i;
	
	pthread_mutex_lock( &mutex );
	for ( i = 0; i < NR; i++ )
		cnt++;

	pthread_mutex_unlock( &mutex );

	return NULL;
}
